home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / examples / process / part01
Encoding:
Text File  |  1990-05-11  |  23.5 KB  |  518 lines

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i168: process - spawn multiple child processes, keeping track of them, Part01/01
  5. Message-ID: <12485@xanth.cs.odu.edu>
  6. Date: 11 May 90 00:52:48 GMT
  7. Sender: news@cs.odu.edu
  8. Reply-To: rickf@theweav.cts.com (Rick Flower)
  9. Lines: 504
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: rickf@theweav.cts.com (Rick Flower)
  15. Posting-number: Volume 90, Issue 168
  16. Archive-name: examples/process/part01
  17.  
  18. This Routine will Spawn a "child" process multiple times and attempt to
  19. keep track of each of the various processes that have been started at
  20. that point.  The program basically creates a "modified" workbench startup
  21. message that is sent to each routine (there is a different message for
  22. each process that is spawned -- that way you can send different data to
  23. the different processes) and that routine "reads" the extra information
  24. from the WBStartup Message.  This program will then keep an array of
  25. information about the child processes.    After all processes have been
  26. spawned, it will "wait" for each and every child process to complete, and
  27. then delete the memory segments allocated for the child task with the
  28. UnLoadSeg call of AmigaDos.
  29.  
  30. #!/bin/sh
  31. # This is a shell archive.  Remove anything before this line, then unpack
  32. # it by saving it into a file and typing "sh file".  To overwrite existing
  33. # files, type "sh file -c".  You can also feed this as standard input via
  34. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  35. # will see the following message at the end:
  36. #        "End of archive 1 (of 1)."
  37. # Contents:  child.c makefile_child makefile_parent parent.c
  38. # Wrapped by tadguy@xanth on Thu May 10 20:52:31 1990
  39. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  40. if test -f 'child.c' -a "${1}" != "-c" ; then 
  41.   echo shar: Will not clobber existing file \"'child.c'\"
  42. else
  43. echo shar: Extracting \"'child.c'\" \(6295 characters\)
  44. sed "s/^X//" >'child.c' <<'END_OF_FILE'
  45. X/*lint -idh0:lc/compiler_headers/                                          */
  46. X/*lint -e562 assume ellipsis after comma                                   */
  47. X/*lint -e607 allow parameter substitution                                  */
  48. X/*lint -e537 allow repeated include files                                  */
  49. X/*lint -e544 allow text on #endif lines                                    */
  50. X/*lint -e565 allow use of struct ptrs within prototypes before definition  */
  51. X/*lint +fvr                                                                */
  52. X
  53. X/****************************************************************************
  54. X*                            FILE : CHILD.C                   March 21,1990 *
  55. X*---------------------------------------------------------------------------*
  56. X* This Routine is made to do true Multi-Tasking within the Amiga Dos System *
  57. X* It has the code specially written to make sure that NONE of the variables *
  58. X* used are global and the only variables used are dynamically allocated.    *
  59. X* The only variables that ARE global are static strings, etc. that won't be *
  60. X* changing at all through program operation.                                *
  61. X*---------------------------------------------------------------------------*
  62. X* This Routine was put together with many hours of piecing together parts   *
  63. X* of code from various authors (many of which I can't remember anymore (:-<)*
  64. X* some of the info coming from C-A and much of it coming from other sources *
  65. X* I would certainly like to thank those of you out there that donate your   *
  66. X* own code so that others (like myself!) can learn more about the Amiga!    *
  67. X*                                                                           *
  68. X*                               DISCLAIMER                                  *
  69. X*                                                                           *
  70. X* This program is put into the Public Domain AS-IS and is NOT guaranteed to *
  71. X* be free from bugs,etc.. (insert standard BS here!)                        *
  72. X*                                                                           *
  73. X* Rick Flower                                                               *
  74. X* P.O. Box 3907                                                             *
  75. X* Torrance, Ca. 90510                                                       *
  76. X* UUCP : {hplabs!hp-sdd ucsd nosc}!crash!theweav!rickf                      *                                                    
  77. X****************************************************************************/
  78. X#include <stdio.h>
  79. X#include <stdlib.h>
  80. X#include <fcntl.h>
  81. X#include <exec/types.h>
  82. X#include <exec/ports.h>
  83. X#include <exec/io.h>
  84. X#include <exec/memory.h>
  85. X#include <workbench/startup.h>
  86. X#include <proto/dos.h>
  87. X#include <proto/exec.h>
  88. X
  89. X#define strlen __builtin_strlen
  90. Xextern int strlen __ARGS((char *));
  91. Xvoid    main(void);
  92. Xextern     struct WBStartup *WBenchMsg;
  93. X
  94. X/*---------------------------------------------------------------------*/
  95. X/*- The Following Structure will Enable the Parent Program to Send us -*/
  96. X/*- a Set of Parameters through the typical Workbench Startup Message -*/
  97. X/*- without Sending another message to/from the parent.. The Address  -*/
  98. X/*- of the WBStartup Message is Stored by the Startup Code (Asm code) -*/
  99. X/*- in the External Global Variable called WBenchMsg.. So, we just    -*/
  100. X/*- Cast it to another data type and we're all set!                   -*/
  101. X/*-                                                                   -*/
  102. X/*- For Usage other than this demo code, just remove the x_coord and  -*/
  103. X/*- y_coord variables and place your own variables to be passed to the-*/
  104. X/*- child routine.. MAKE SURE THAT THE PARENT ALSO HAS THESE!!        -*/
  105. X/*---------------------------------------------------------------------*/
  106. Xstruct    OurWBenchMsg
  107. X{
  108. X    struct    WBStartup  MyMess;    /*- Actual Workbench Startup Msg -*/
  109. X    long             process_num;    /*- Process Number from Parent   -*/
  110. X    int         x_coord;    /*- X Coordinate for Position    -*/
  111. X    int             y_coord;    /*- Y Coordinate for Position    -*/
  112. X};
  113. X
  114. X/*------------------------------------------------------------------------*/
  115. X/*- The Following Line of Code Tells the Compiler to use THIS Version of -*/
  116. X/*- "_main" Instead of the Library version.  We have refefined this to   -*/
  117. X/*- just call the TinyMain routine instead to make it NOT open any I/O   -*/
  118. X/*- Windows... (This suggestion was read on the Lattice Support BBS)     -*/
  119. X/*------------------------------------------------------------------------*/
  120. Xvoid     _main(char *cl) { _tinymain(cl); }
  121. X
  122. X/*------------------------------------------------------------------------*/
  123. X/*- The Following Structure is a Dynamically Allocated structure that we -*/
  124. X/*- use for ANY and ALL variables used in this program so no variables   -*/
  125. X/*- can overlap and harm another executing child process of this code    -*/
  126. X/*------------------------------------------------------------------------*/
  127. Xstruct    InternalStruct
  128. X{
  129. X    struct    OurWBenchMsg     *MyMess;
  130. X    char    window[80];
  131. X    char    buffer[80];
  132. X    long    i;
  133. X    int    fh;
  134. X    FILE    *fp;
  135. X};
  136. X
  137. Xstruct InternalStruct *IS;
  138. X
  139. X/*-------------------------------------------------------------------------*/
  140. X/*-                      Main Routine Starts Here!                        -*/
  141. X/*-------------------------------------------------------------------------*/
  142. Xvoid    main(void)
  143. X{
  144. X    IS = AllocMem((ULONG)sizeof(struct InternalStruct),MEMF_CLEAR | MEMF_PUBLIC);
  145. X    if (IS)
  146. X    {
  147. X       IS->MyMess = (struct OurWBenchMsg *)WBenchMsg;
  148. X       sprintf(IS->window,"con:%d/%d/200/70/TEMP-%ld",IS->MyMess->x_coord,IS->MyMess->y_coord,IS->MyMess->process_num);
  149. X       sprintf(IS->buffer,"Process # %04ld\n",IS->MyMess->process_num);
  150. X       IS->fh = open(IS->window,O_RDWR,0);
  151. X       if (IS->fh)
  152. X       {
  153. X          for (IS->i = 0; IS->i < 15; IS->i++)
  154. X             write(IS->fh,IS->buffer,strlen(IS->buffer));
  155. X          sprintf(IS->buffer,"vd0:temp%04ld.dat",IS->MyMess->process_num);
  156. X          IS->fp = fopen(IS->buffer,"w");
  157. X          if (IS->fp)
  158. X          {
  159. X             fprintf(IS->fp,"This Message is from Process #%ld\n\n",IS->MyMess->process_num);
  160. X             fclose(IS->fp);
  161. X          }
  162. X          write(IS->fh,IS->buffer,strlen(IS->buffer));
  163. X          for (IS->i = 0; IS->i < 150000; IS->i++) ;
  164. X          close(IS->fh);
  165. X       }
  166. X       FreeMem(IS,(ULONG)sizeof(struct InternalStruct));
  167. X    }
  168. X}
  169. END_OF_FILE
  170. if test 6295 -ne `wc -c <'child.c'`; then
  171.     echo shar: \"'child.c'\" unpacked with wrong size!
  172. fi
  173. # end of 'child.c'
  174. fi
  175. if test -f 'makefile_child' -a "${1}" != "-c" ; then 
  176.   echo shar: Will not clobber existing file \"'makefile_child'\"
  177. else
  178. echo shar: Extracting \"'makefile_child'\" \(1064 characters\)
  179. sed "s/^X//" >'makefile_child' <<'END_OF_FILE'
  180. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  181. X#%                        Make the "child" Program                          %
  182. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  183. X
  184. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  185. X#% Define Global Logical Assignments %
  186. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  187. XBLINK         = LC:blink
  188. XLC_REGFLAGS  = -cfist -v
  189. XLC         = LC:lc
  190. XLIB         = LIB:
  191. X
  192. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  193. X#%                 Define How to Link the Entire Program #                  %
  194. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  195. Xchild:    child.o
  196. X    BLINK      <WITH <
  197. X    FROM     $(LIB)catchresnr.o + child.o
  198. X    TO     child LIBRARY LIB:lc.lib LIB:amiga.lib
  199. X<
  200. X
  201. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  202. X#%                       What Each File Depends On                          %
  203. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  204. Xchild.o    : child.c
  205. X   $(LC) $(LC_REGFLAGS) child
  206. X
  207. END_OF_FILE
  208. if test 1064 -ne `wc -c <'makefile_child'`; then
  209.     echo shar: \"'makefile_child'\" unpacked with wrong size!
  210. fi
  211. # end of 'makefile_child'
  212. fi
  213. if test -f 'makefile_parent' -a "${1}" != "-c" ; then 
  214.   echo shar: Will not clobber existing file \"'makefile_parent'\"
  215. else
  216. echo shar: Extracting \"'makefile_parent'\" \(1094 characters\)
  217. sed "s/^X//" >'makefile_parent' <<'END_OF_FILE'
  218. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  219. X#%                       Make the "parent" Program                          %
  220. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  221. X
  222. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  223. X#% Define Global Logical Assignments %
  224. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  225. XBLINK         = LC:blink
  226. XLC_REGFLAGS  = -cfist -b0 -m0 -r0 -s 
  227. XLC_DBGFLAGS  = -b0 -m0 -r0 -s -d4
  228. XLC         = LC:lc
  229. XLIB         = LIB:
  230. X
  231. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  232. X#%                 Define How to Link the Entire Program #                  %
  233. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  234. Xparent:    parent.o
  235. X    BLINK     <WITH <
  236. X    FROM     $(LIB)c.o + parent.o
  237. X    TO     parent LIBRARY LIB:lc.lib
  238. X<
  239. X
  240. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  241. X#%                       What Each File Depends On                          %
  242. X#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  243. Xparent.o    : parent.c
  244. X   $(LC) $(LC_REGFLAGS) parent
  245. X
  246. END_OF_FILE
  247. if test 1094 -ne `wc -c <'makefile_parent'`; then
  248.     echo shar: \"'makefile_parent'\" unpacked with wrong size!
  249. fi
  250. # end of 'makefile_parent'
  251. fi
  252. if test -f 'parent.c' -a "${1}" != "-c" ; then 
  253.   echo shar: Will not clobber existing file \"'parent.c'\"
  254. else
  255. echo shar: Extracting \"'parent.c'\" \(11246 characters\)
  256. sed "s/^X//" >'parent.c' <<'END_OF_FILE'
  257. X/*lint -idh0:lc/compiler_headers/                                          */
  258. X/*lint -e562 assume ellipsis after comma                                   */
  259. X/*lint -e607 allow parameter substitution                                  */
  260. X/*lint -e537 allow repeated include files                                  */
  261. X/*lint -e544 allow text on #endif lines                                    */
  262. X/*lint -e565 allow use of struct ptrs within prototypes before definition  */
  263. X/*lint +fvr                                                                */
  264. X
  265. X/****************************************************************************
  266. X*                            FILE : PARENT.C                  March 21,1990 *
  267. X*---------------------------------------------------------------------------*
  268. X* This Routine will Spawn a "child" process multiple times and attempt to   *
  269. X* keep track of each of the various processes that have been started at     *
  270. X* that point.  The program basically creates a "modified" workbench startup *
  271. X* message that is sent to each routine (there is a different message for    *
  272. X* each process that is spawned -- that way you can send different data to   *
  273. X* the different processes) and that routine "reads" the extra information   *
  274. X* from the WBStartup Message.  This program will then keep an array of      *
  275. X* information about the child processes.  After all processes have been     *
  276. X* spawned, it will "wait" for each and every child process to complete, and *
  277. X* then delete the memory segments allocated for the child task with the     *
  278. X* UnLoadSeg call of AmigaDos.                                               *
  279. X*---------------------------------------------------------------------------*
  280. X* This Routine was put together with many hours of piecing together parts   *
  281. X* of code from various authors (many of which I can't remember anymore (:-<)*
  282. X* some of the info coming from C-A and much of it coming from other sources.*
  283. X* I would certainly like to thank those of you out there that donate your   *
  284. X* own code so that others (like myself!) can learn more about the Amiga!    *
  285. X*                                                                           *
  286. X*                               DISCLAIMER                                  *
  287. X*                                                                           *
  288. X* This program is put into the Public Domain AS-IS and is NOT guaranteed to *
  289. X* be free from bugs,etc.. (insert standard BS here!)                        *
  290. X*                                                                           *
  291. X* Rick Flower                                                               *
  292. X* P.O. Box 3907                                                             *
  293. X* Torrance, Ca. 90510                                                       *
  294. X* UUCP : {hplabs!hp-sdd ucsd nosc}!crash!theweav!rickf                      *                                                    
  295. X****************************************************************************/
  296. X#include <stdio.h>
  297. X#include <stdlib.h>
  298. X#include <exec/types.h>
  299. X#include <exec/ports.h>
  300. X#include <exec/io.h>
  301. X#include <exec/memory.h>
  302. X#include <devices/serial.h>
  303. X#include <intuition/intuition.h>
  304. X#include <libraries/dosextens.h>
  305. X#include <workbench/startup.h>
  306. X#include <proto/dos.h>
  307. X#include <proto/exec.h>
  308. X#include <proto/intuition.h>
  309. X#include <proto/graphics.h>
  310. X
  311. X/*------------------------------------------------------*/
  312. X/*- Put all Defines Here for PreProcessor Substitution -*/
  313. X/*------------------------------------------------------*/
  314. X#define FILE_2_LOAD  "child"            /*- Filename of Child to Load -*/
  315. X#define STACK_SIZE   5000L            /*- Default Child's Stack Size-*/
  316. X
  317. X/*---------------------------------------------------------------------*/
  318. X/*- The Following Structure will Enable the Parent Program to Send us -*/
  319. X/*- a Set of Parameters through the typical Workbench Startup Message -*/
  320. X/*- without Sending another message to/from the parent.. The Address  -*/
  321. X/*- of the WBStartup Message is Stored by the Startup Code (Asm code) -*/
  322. X/*- in the External Global Variable called WBenchMsg.. So, we just    -*/
  323. X/*- Cast it to another data type and we're all set!                   -*/
  324. X/*-                                                                   -*/
  325. X/*- For Usage other than this demo code, just remove the x_coord and  -*/
  326. X/*- y_coord variables and place your own variables to be passed to the-*/
  327. X/*- child routine.. MAKE SURE THAT THE CHILD ALSO HAS THESE!!         -*/
  328. X/*---------------------------------------------------------------------*/
  329. Xstruct    OurWBenchMsg
  330. X{
  331. X    struct    WBStartup  MyMess;    /*- Actual Workbench Startup Msg -*/
  332. X    long             process_num;    /*- Process Number from Parent   -*/
  333. X    int         x_coord;    /*- X Coordinate for Position    -*/
  334. X    int             y_coord;    /*- Y Coordinate for Position    -*/
  335. X};
  336. X
  337. X/*-------------------------------------------------------------------------*/
  338. X/*- The Following Structure Allows the Parent Process to Keep Track on a  -*/
  339. X/*- few items that are unique to each child process spawned.  Mainly, the -*/
  340. X/*- Message Port of the Child and the WBenchStartup Message that is sent  -*/
  341. X/*- along with keeping tabs on which child is which..                      -*/
  342. X/*-------------------------------------------------------------------------*/
  343. Xstruct    MyChild
  344. X{
  345. X    struct    MsgPort      *Port;
  346. X    struct    OurWBenchMsg *StartMsg;
  347. X    long    ChildNumber;
  348. X};
  349. X
  350. X/*------------------------------------------*/
  351. X/*- Define All Program Function Prototypes -*/
  352. X/*------------------------------------------*/
  353. Xchar     *Initialize_System(void);
  354. Xint    Spawn_Child(char *process_name);
  355. Xvoid    DeInitialize_System(void);
  356. X
  357. X/*--------------------------------------------*/
  358. X/*- Define Global Variables for System Usage -*/
  359. X/*--------------------------------------------*/
  360. Xstruct    MsgPort *Parent_Port;
  361. Xstruct    MyChild    *kids[32] = { NULL };
  362. Xint        CurrentKid;
  363. XBPTR        Child_Code_Addr;
  364. Xlong         ChildNumber = 0;
  365. Xint            x_coord = 10, y_coord = 10;
  366. X
  367. X/*----------------------------------------------------------------------*/
  368. X/*- Open Required Ports & Allocate Workbench Message & Load Child Code -*/
  369. X/*----------------------------------------------------------------------*/
  370. Xchar     *Initialize_System(void)
  371. X{
  372. Xchar    *p = NULL;
  373. X
  374. X/*------------------------------------------------------------------*/
  375. X/*- Open a Message Port for Communication with all Child Processes -*/
  376. X/*------------------------------------------------------------------*/
  377. X    Parent_Port = CreatePort((char *)"WWIV_Main",0L);
  378. X    if (!Parent_Port) p = (char *)"Unable to Open a Message Port..\n";
  379. X
  380. X/*-----------------------------------------------------*/
  381. X/*- Attempt to Load the Program into a Memory Segment -*/
  382. X/*-----------------------------------------------------*/
  383. X    if (!p)
  384. X    {
  385. X        Child_Code_Addr = LoadSeg(FILE_2_LOAD);
  386. X       if (!Child_Code_Addr)
  387. X       {
  388. X          DeletePort(Parent_Port);
  389. X          p = (char *)"Unable to Load Child Code..\n";
  390. X       }
  391. X    }
  392. X    CurrentKid = -1;
  393. X    return(p);
  394. X}
  395. X
  396. X/*------------------------------------------------------------------------*/
  397. X/*- Spawn a Child Process & Save Information for Child Resource Tracking -*/
  398. X/*------------------------------------------------------------------------*/
  399. Xint    Spawn_Child(char *process_name)
  400. X{
  401. X    CurrentKid++;
  402. X    kids[CurrentKid] = AllocMem((ULONG)sizeof(struct MyChild),MEMF_CLEAR | MEMF_PUBLIC);
  403. X    if ( !kids[CurrentKid] ) { CurrentKid--; return(1); }
  404. X
  405. X/*---------------------------------------------------------------------*/
  406. X/*- Allocate Memory for the Workbench Startup Message & Initialize it -*/
  407. X/*---------------------------------------------------------------------*/
  408. X    kids[CurrentKid]->StartMsg = AllocMem((ULONG)sizeof(struct OurWBenchMsg),MEMF_CLEAR | MEMF_PUBLIC);
  409. X    if (!kids[CurrentKid]->StartMsg) return(1);
  410. X    kids[CurrentKid]->StartMsg->MyMess.sm_Message.mn_ReplyPort = Parent_Port;
  411. X    kids[CurrentKid]->StartMsg->MyMess.sm_Message.mn_Length    = sizeof(struct OurWBenchMsg);
  412. X
  413. X/*----------------------------------------------------------*/
  414. X/*- Create and Start the Child Process & Check for Success -*/
  415. X/*----------------------------------------------------------*/
  416. X    kids[CurrentKid]->Port = CreateProc(process_name,0L,Child_Code_Addr,STACK_SIZE);
  417. X    if (kids[CurrentKid]->Port) 
  418. X    {
  419. X       ChildNumber++;
  420. X       kids[CurrentKid]->ChildNumber            = ChildNumber;
  421. X       kids[CurrentKid]->StartMsg->process_num = kids[CurrentKid]->ChildNumber;
  422. X       kids[CurrentKid]->StartMsg->x_coord     = x_coord;
  423. X       kids[CurrentKid]->StartMsg->y_coord     = y_coord;
  424. X       x_coord += 20;
  425. X       y_coord += 20;
  426. X       printf("Spawning Child #%08ld - %04d : %04d\r",
  427. X              kids[CurrentKid]->ChildNumber,x_coord,y_coord);
  428. X       PutMsg(kids[CurrentKid]->Port,(struct Message *)kids[CurrentKid]->StartMsg);
  429. X       return(0);
  430. X    }
  431. X    else return(1);
  432. X}
  433. X
  434. X/*-----------------------------------------------------------------------*/
  435. X/*- Unload the Program Segments, Free Workbench Msg Memory, Delete Port -*/
  436. X/*-----------------------------------------------------------------------*/
  437. Xvoid    DeInitialize_System(void)
  438. X{
  439. Xstruct    OurWBenchMsg *temp;
  440. Xint    i,a;
  441. X
  442. X/*------------------------------------------------------------------------*/
  443. X/*- Wait for Each and Every Child to Complete and ReplyMsg() to Us Here! -*/
  444. X/*------------------------------------------------------------------------*/
  445. X    for (i=0; i < ChildNumber; i++)
  446. X    {
  447. X       printf("\nWaiting for a Child to Complete..\n");
  448. X       WaitPort(Parent_Port); 
  449. X           temp = (struct OurWBenchMsg *)GetMsg(Parent_Port);
  450. X/*----------------------------------------------------------------------*/
  451. X/*- See which child Came in so we only free the resources it used, not -*/
  452. X/*- others                                                             -*/
  453. X/*----------------------------------------------------------------------*/
  454. X       a = 0;
  455. X       while (kids[a]->StartMsg->process_num != temp->process_num) a++;
  456. X       printf("Child Structure Located @ Address #%02d\n",a);
  457. X       if (kids[a]->StartMsg) FreeMem(kids[a]->StartMsg,(ULONG)sizeof(struct OurWBenchMsg));
  458. X        if (kids[a])           FreeMem(kids[a],(ULONG)sizeof(struct MyChild));
  459. X    }
  460. X
  461. X/*------------------------------------------------------------------*/
  462. X/*- Unload the Child's Code (all children MUST be done Executing!) -*/
  463. X/*------------------------------------------------------------------*/
  464. X    printf("\nUnloading Children's Code, & Deinitializing System..\n");
  465. X    UnLoadSeg(Child_Code_Addr);            /*- Dump Program Segments -*/
  466. X    DeletePort(Parent_Port);            /*- Delete Communications!-*/
  467. X}
  468. X
  469. X/*-------------------------------------------------------------------------*/
  470. X/*-                      Main Routine Starts Here!                        -*/
  471. X/*-------------------------------------------------------------------------*/
  472. Xvoid    main(void)
  473. X{
  474. Xchar    *p;
  475. X
  476. X    p = Initialize_System();
  477. X    if (p) 
  478. X       printf("%s\n\n",p);
  479. X    else
  480. X    {
  481. X       printf("Initialization Complete...\n");
  482. X       if (Spawn_Child("Child_1") == 1) printf("Error!\n");
  483. X       if (Spawn_Child("Child_2") == 1) printf("Error!\n");
  484. X       if (Spawn_Child("Child_3") == 1) printf("Error!\n");
  485. X       if (Spawn_Child("Child_4") == 1) printf("Error!\n");
  486. X       if (Spawn_Child("Child_5") == 1) printf("Error!\n");
  487. X       if (Spawn_Child("Child_6") == 1) printf("Error!\n");
  488. X       DeInitialize_System();
  489. X    }
  490. X}
  491. END_OF_FILE
  492. if test 11246 -ne `wc -c <'parent.c'`; then
  493.     echo shar: \"'parent.c'\" unpacked with wrong size!
  494. fi
  495. # end of 'parent.c'
  496. fi
  497. echo shar: End of archive 1 \(of 1\).
  498. cp /dev/null ark1isdone
  499. MISSING=""
  500. for I in 1 ; do
  501.     if test ! -f ark${I}isdone ; then
  502.     MISSING="${MISSING} ${I}"
  503.     fi
  504. done
  505. if test "${MISSING}" = "" ; then
  506.     echo You have the archive.
  507.     rm -f ark[1-9]isdone
  508. else
  509.     echo You still need to unpack the following archives:
  510.     echo "        " ${MISSING}
  511. fi
  512. ##  End of shell archive.
  513. exit 0
  514. -- 
  515. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  516. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  517. Post requests for sources, and general discussion to comp.sys.amiga.
  518.